import java.util.*;
import java.util.function.BiConsumer;

class Student{
    public int id;
    public String name;

    public Student(int id, String name){
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "(id:" + id + ",name:" + name + ")";
    }
}


public class Main {
    // 测试使用Set的部分方法
    public static void main(String[] args) {
        // boolean addAll方法
        Set<Integer> set1 = new TreeSet<>();
        set1.add(3);
        set1.add(5);
        Set<Integer> set2 = new TreeSet<>();
        set2.add(1);
        set2.add(5);

        set1.addAll(set2);
        System.out.println(set1);

        // Object[] toArray 方法
        Object[] objects = set1.toArray();
        for (Object o : objects) {
            System.out.print(o + " ");
        }

    }


    // 测试使用Map的部分方法
    public static void main2(String[] args) {
        Map<Integer,String> map1 = new TreeMap<>();
        map1.put(1,"张三");
        map1.put(3,"lisi");
        map1.put(5,"lisi");

        System.out.println("keySet获取map的所有key的不重复集合");
        Set<Integer> keySets = map1.keySet();
        System.out.println(keySets);

        System.out.println("values获取map所有value的可重复集合");
        Collection<String> values = map1.values();
        System.out.println(values);

        System.out.println("entrySet获取所有的key-value映射关系");
        // entrySet方法功能：把map的key和value打包成Map.Entry<Integer,String>，然后放入Set中作为Set的key
        Set<Map.Entry<Integer, String>> entries = map1.entrySet();
        System.out.println("遍历1 toString:");
        System.out.println(entries);
        System.out.println("遍历2 foreach:");
        for (Map.Entry<Integer,String> entry : entries) {
            System.out.print(entry.getKey() + ":" + entry.getValue() + "   ");
        }
    }




    // 测试Map和Set实现类中元素重复的情况
    public static void main1(String[] args) {
        Map<Integer,String> map1 = new TreeMap<>();
        map1.put(5,"zhangsan");
        map1.put(5,"lisi");

        System.out.println(map1);


        Map<Integer,String> map2 = new HashMap<>();
        map2.put(1,"lisi");
        map2.put(1,"zhangsan");
        System.out.println(map2);


        Set<Integer> set1 = new TreeSet<>();
        set1.add(3);
        set1.add(3);
        System.out.println(set1);


        Set<Integer> set2 = new HashSet<>();
        set2.add(2);
        set2.add(2);
        System.out.println(set2);
    }
}
